home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / analog / Source / formgen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-07  |  9.2 KB  |  217 lines

  1. /*** analog 1.9beta ***/
  2. /* Please read Readme.html, or http://www.statslab.cam.ac.uk/~sret1/analog/  */
  3.  
  4. /*** formgen.c; generate a form for the analog form interface ***/
  5.  
  6. #include "analhea2.h"
  7.  
  8. void genopts(FILE *outf, char name[17], char plural[16], int sortby,
  9.          char codeletter)
  10. {
  11.   fprintf(outf, "\n<h3>%s options</h3>\n\n", name);
  12.   fprintf(outf, "Sort the %s \n<select name=%cs size=1>\n", name, codeletter);
  13.   fprintf(outf, "<option value=2%s>alphabetically (*)\n",
  14.       (sortby==ALPHABETICAL)?" selected":"");
  15.   fprintf(outf, "<option value=1%s>by volume of traffic (+)\n",
  16.       (sortby==BYBYTES)?" selected":"");
  17.   fprintf(outf, "<option value=0%s>by number of requests (*)\n",
  18.       (sortby==BYREQUESTS)?" selected":"");
  19.   fprintf(outf, "</select>\n");
  20.   fprintf(outf, "<br>(*) Include all %s with at least\n", plural);
  21.   fprintf(outf, "<input type=TEXT name=\"%ca\" maxlength=6 size=6> requests\n",
  22.       codeletter);
  23.   fprintf(outf, "<b>or</b> the top ");
  24.   fprintf(outf, "<input type=TEXT name=\"%cb\" maxlength=3 size=3> %s.\n",
  25.       codeletter, plural);
  26.   fprintf(outf, "<br>(*) Include all %s with at least\n", plural);
  27.   fprintf(outf, "<input type=TEXT name=\"%cc\" maxlength=6 size=6> bytes\n",
  28.       codeletter);
  29.   fprintf(outf, "transferred <b>or</b> the top ");
  30.   fprintf(outf, "<input type=TEXT name=\"%cd\" maxlength=3 size=3> %s.\n",
  31.       codeletter, plural);
  32. }
  33.  
  34. void formgen(void)
  35. {
  36.   extern flag xq, mq, Wq, dq, Dq, hq, oq, Sq, iq, rq, Bq, bq, fq, eq, cq;
  37.   extern char reportorder[];
  38.   extern int domsortby, dirsortby, hostsortby, reqsortby, refsortby;
  39.   extern int browsortby, fullbrowsortby;
  40.   extern int dirlevel, reqtype, kq;
  41.   extern char hostname[], hosturl[], logourl[], commandname[];
  42.   extern char outfile[];
  43.   extern struct timestruct fromtime, totime;
  44.  
  45.   char *ro;
  46.   FILE *outf;
  47.  
  48.   if (STREQ(outfile, "stdout"))
  49.     outf = stdout;
  50.  
  51.   else if ((outf = fopen(outfile, "w")) == NULL) {
  52.     fprintf(stderr, "%s: Error: failed to open output file %s for writing.\n",
  53.         commandname, outfile);
  54.     exit(ERR);  /* shouldn't get here because also tested at the beginning */
  55.   }
  56.  
  57.   fprintf(outf, "<html><head>\n");
  58.   fprintf(outf, "<title>Analog form interface</title>\n");
  59.   fprintf(outf, "</head>\n\n");
  60.   fprintf(outf, "<body>\n");
  61.   if (hosturl[0] == '-')
  62.     fprintf(outf, "<h1><img src=\"%s\" alt=\"\"> Analog form interface for %s</h1>\n",
  63.        logourl, hostname);
  64.   else
  65.     fprintf(outf, "<h1><img src=\"%s\" alt=\"\"> Analog form interface for <a HREF=\"%s\">%s</a></h1>\n",
  66.        logourl, hosturl, hostname);    
  67.   fprintf(outf, "<form action=\""FORMPROG"\" method=\"GET\">\n");
  68.   fprintf(outf, "<hr><i>You can set any options you like below. But they should all be set to\n");
  69.   fprintf(outf, "sensible default values, so you can ignore any of them too.</i>\n");
  70.   fprintf(outf, "<hr>\n<h2>1. Report choices</h2>\n");
  71.   fprintf(outf, "<i>See <a href=\"http://www.statslab.cam.ac.uk/~sret1/analog/\">the analog\n");
  72.   fprintf(outf, "home page</a> for the meanings of the various reports.</i>\n\n");
  73.   fprintf(outf, "<p>\n<h3>Which reports do you want to see?</h3>\n");
  74.   fprintf(outf, "<INPUT TYPE=checkbox NAME=\"xq\" VALUE=1%s>General statistics?\n",
  75.      xq?" checked":"");
  76.   
  77.   for (ro = reportorder; *ro != '\0'; ro++) {
  78.     switch(*ro) {
  79.     case 'b':
  80.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"bq\" VALUE=1%s>Browser summary?\n", bq?" checked":"");
  81.       break;
  82.     case 'B':
  83.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"Bq\" VALUE=1%s>Browser report?\n", Bq?" checked":"");
  84.       break;
  85.     case 'c':
  86.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"cq\" VALUE=1%s>Status code report?\n", cq?" checked":"");
  87.       break;
  88.     case 'd':
  89.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"dq\" VALUE=1%s>Daily summary?\n", dq?" checked":"");
  90.       break;
  91.     case 'D':
  92.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"Dq\" VALUE=1%s>Daily report? (NB: Can be long)\n", Dq?" checked":"");
  93.       break;
  94.     case 'e':
  95.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"eq\" VALUE=1%s>Error report?\n", eq?" checked":"");
  96.       break;
  97.     case 'f':
  98.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"fq\" VALUE=1%s>Referer report?\n", fq?" checked":"");
  99.       break;    /* case 'H', hourly report, deliberately omitted */
  100.     case 'h':
  101.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"hq\" VALUE=1%s>Hourly summary?\n", hq?" checked":"");
  102.       break;
  103.     case 'i':
  104.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"iq\" VALUE=1%s>Directory report?\n", iq?" checked":"");
  105.       break;
  106.     case 'm':
  107.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"mq\" VALUE=1%s>Monthly report?\n", mq?" checked":"");
  108.       break;
  109.     case 'o':
  110.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"oq\" VALUE=1%s>Domain report?\n", oq?" checked":"");
  111.       break;
  112.     case 'r':
  113.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"rq\" VALUE=1%s>Request report?\n", rq?" checked":"");
  114.       break;
  115.     case 'S':
  116.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"Sq\" VALUE=1%s>Host report? (NB: Can be long)\n", Sq?" checked":"");
  117.       break;
  118.     case 'W':
  119.       fprintf(outf, "<BR><INPUT TYPE=checkbox NAME=\"Wq\" VALUE=1%s>Weekly report?\n", Wq?" checked":"");
  120.       break;
  121.     }
  122.   }
  123.  
  124.   fprintf(outf, "<p><i>You can now fill in the options below for individual reports.\n");
  125.   fprintf(outf, "You can fill in the </i>(+)<i> or </i>(*)<i> in each section according to which sort method you select.\n");
  126.   fprintf(outf, "You can use <input type=TEXT name=\"vo\" maxlength=4 size=4 value=\"10M\"> bytes to mean 10 Megabytes etc.</i>\n");
  127.  
  128.   fprintf(outf, "<hr>\n<h2>2. Detailed report options</h2>\n");
  129.   for (ro = reportorder; *ro != '\0'; ro++) {
  130.     switch(*ro) {
  131.     case 'b':
  132.       genopts(outf, "Browser summary", "browsers", browsortby, 'b');
  133.       break;
  134.     case 'B':
  135.       genopts(outf, "Browser report", "browsers", fullbrowsortby, 'B');
  136.       break;
  137.     case 'f':
  138.       genopts(outf, "Referer report", "referring URLs", refsortby, 'f');
  139.       break;
  140.     case 'i':
  141.       genopts(outf, "Directory report", "directories", dirsortby, 'i');
  142.       fprintf(outf, "<br>Print directories to depth ");
  143.       fprintf(outf, "<input type=text name=\"ie\" maxlength=1 size=1 value=%d>\n", dirlevel);
  144.       break;
  145.     case 'o':
  146.       genopts(outf, "Domain report", "domains", domsortby, 'o');
  147.       break;
  148.     case 'r':
  149.       genopts(outf, "Request report", "requests", reqsortby, 'r');
  150.       fprintf(outf, "<br>Show\n");
  151.       fprintf(outf, "<select name=\"rt\" size=1>\n");
  152.       fprintf(outf, "<option value=\"f\"%s>all files\n",
  153.          reqtype == ALL?" selected":"");
  154.       fprintf(outf, "<option value=\"p\"%s>pages only\n",
  155.          reqtype == PAGES?" selected":"");
  156.       fprintf(outf, "</select>\n; include links to\n");
  157.       fprintf(outf, "<select name=\"rl\" size=1>\n");
  158.       fprintf(outf, "<option value=\"f\"%s>all files\n",
  159.          kq == ALL?" selected":"");
  160.       fprintf(outf, "<option value=\"p\"%s>pages only\n",
  161.          kq == ON?" selected":"");
  162.       fprintf(outf, "<option value=\"n\"%s>no files\n",
  163.          kq == OFF?" selected":"");
  164.       fprintf(outf, "</select>\n");
  165.  
  166.       break;
  167.     case 'S':
  168.       genopts(outf, "Host report", "hosts", hostsortby, 'S');
  169.       break;
  170.  
  171.     }
  172.   }
  173.  
  174.  
  175.   fprintf(outf, "<hr>\n\n<h2>3. Analysing only part of the logfile</h2>\n");
  176.   fprintf(outf, "<b>Only certain dates</b>\n");
  177.   fprintf(outf, "<br>You can analyse only the requests from certain dates.\n");
  178.   fprintf(outf, "Enter the range of dates below in the from <i>yymmdd</i>;\n");
  179.   fprintf(outf, "e.g., 950701 for 1st July 1995 (or fill in just one box\n");
  180.   fprintf(outf, "to limit the range of dates on just one side).");
  181.   fprintf(outf, "<br>From <input type=TEXT name=\"fr\" maxlength=10 size=6");
  182.   if (fromtime.code > -INFINITY)
  183.     fprintf(outf, " value=\"%02d%02d%02d\"", fromtime.year % 100,
  184.        fromtime.monthno + 1, fromtime.date);
  185.   fprintf(outf, ">\nto <input type=TEXT name=\"to\" maxlength=10 size=6");
  186.   if (totime.code < INFINITY)
  187.     fprintf(outf, " value=\"%02d%02d%02d\"", totime.year % 100,
  188.        totime.monthno + 1, totime.date);
  189.   fprintf(outf, ">\n\n");
  190.  
  191.   fprintf(outf, "<p><b>Only certain files</b>\n");
  192.   fprintf(outf, "<br>Only look at the following files (list, separated by commas; can contain wild character *)\n");
  193.   fprintf(outf, "<br><input type=TEXT name=\"fy\" size=60>\n");
  194.   fprintf(outf, "<br>Ignore the following files\n");
  195.   fprintf(outf, "<br><input type=TEXT name=\"fi\" size=60>\n");
  196.  
  197.   fprintf(outf, "<hr><h2>4. Layout</h2>\n");
  198.  
  199.   fprintf(outf, "<b>Your organisation's name</b> (for the title of the page)\n");
  200.   fprintf(outf, "<input type=TEXT name=\"or\" value=\"%s\" size=60>\n",
  201.      hostname);
  202.  
  203.   fprintf(outf, "<p><b>Your organisation's home page</b> (leave blank for none)\n");
  204.   fprintf(outf, "<br>URL: <input type=TEXT name=\"ho\" value=\"%s\" size=60>\n",
  205.          hosturl);
  206.  
  207.   fprintf(outf, "<hr><input type=hidden name=\"TZ\" value=\"%s\">\n",
  208.          getenv("TZ")!=NULL?getenv("TZ"):"");  /* gets it twice, but easy */
  209.   fprintf(outf, "<input type=submit value=\"Produce statistics\"> ");
  210.   fprintf(outf, "<input type=reset value=\"Reset form\">\n");
  211.   fprintf(outf, "</form>\n");
  212.   fprintf(outf, "<P> <A HREF=\"http://www.webtechs.com/html-val-svc/\">\n");
  213.   fprintf(outf, "<IMG SRC=\"http://www.webtechs.com/html-val-svc/images/valid_html.gif\" ALT=\"HTML 2.0 Compliant!\"></A>\n");
  214.   fprintf(outf, "</body></html>\n");
  215.  
  216. }
  217.